package com.karrysong.blog_springboot.controller;

import com.karrysong.blog_springboot.service.CommentService;
import com.karrysong.blog_springboot.vo.Result;
import com.karrysong.blog_springboot.vo.params.CommentPage;
import com.karrysong.blog_springboot.vo.params.CommentParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: CommentController
 * @Author: KarrySong
 * @Date: 2022/8/6 14:17
 * @Description:
 */
@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @GetMapping("/article/{id}")
    public Result getArticleComments(@PathVariable Long id){
        return commentService.commentsByArticleId(id);
    }

    @PostMapping("/create/change")
    public Result comment(@RequestBody CommentParam commentParam){
        return commentService.comment(commentParam);
    }

    @PostMapping("/admin/all")
    public Result getComments(@RequestBody CommentPage commentPage){
        return commentService.getComments(commentPage);
    }

    @PostMapping("/admin/{id}/{newStatus}")
    public Result changeStatus(@PathVariable("id") Long id, @PathVariable("newStatus") Integer newStatus){
        return commentService.changeCommentStatus(id, newStatus);
    }

    @PostMapping("/admin/delete/{id}")
    public Result deleteComment(@PathVariable("id") Long id){
        return commentService.deleteComment(id);
    }


}
